// 导入语句需要根据实际模块化工具进行调整，例如CommonJS或ES Modules
// const { SlateRange } = require("@wangeditor/editor");
import { SlateRange } from '@wangeditor/editor'
import { message } from 'ant-design-vue';
import BaseFn from '../base-fn'
// const BaseFn = require("../base-fn"); // 假设 BaseFn 是从同一目录下的 base-fn.js 导入的

class MuteFn extends BaseFn {
    constructor(editor) {
        super(editor);
    }

    isDisabled() {
        if (super.isDisabled()) return true;
        const { selection } = this.editor;
        if (!selection) return true;
        if (SlateRange.isExpanded(selection)) {
            message.warn("不能框选文本")
            // emitter.emit("warn", "不能框选文本");
            return true;
        }
        return false;
    }

    exec(opt) {
        this.editor.restoreSelection();
        if (this.isDisabled()) return;

        const node = {
            type: "ssml-break",
            time: opt.value+'ms',
            remark: opt.label,
            children: [{ text: "" }],
        };

        this.editor.insertNode(node);
    }
}

export default MuteFn;
